---
title: Serializer Specification
---

> "Serializer" refers to Graphif Serializer, which has a official implementation [`@graphif/serializer`](/docs/serializer).

This is an object serialization format based on JavaScript.

It has three core concepts: **instance**, **other types**, and **reference**.

## Instance

Instance is a JavaScript object with prototype.

It stores the name of prototype in property `_`, and other properties are stored as key-value pairs.

```json
{
  "_": "ClassName",
  "property1": "value1",
  "property2": 42,
  "property3": true
}
```

Instance is nestable, meaning that properties can be other instances or other types.

```json
{
  "_": "ClassName",
  "property1": {
    "_": "OtherClass",
    "otherProperty": "otherValue"
  },
  "property2": [1, 2, 3],
  "property3": null
}
```

## Other Types

Other values will stored as is, including:

- Primitive types: `string`, `number`, `boolean`, `null`, `undefined`
- Array: `[value1, value2, ...]`
- Plain object (without prototype): `{ key1: value1, key2: value2, ... }`

## Reference

If there are same objects in the serialized data, implementations may store them as references to save space.

A reference is an object with property `$`, which value is a path string to the referred object, and implementations should replace with the referred object.

```json
[
  {
    "_": "ClassName",
    "property": "value",
    "other": {
      "value": 42
    }
  },
  { "$": "/0" },
  { "$": "/0/other" }
]
```

### Path String

Path string is a string that starts with `/`, followed by a series of keys or indices separated by `/`.
